﻿Public Class LoginController
    Inherits Controller
    Implements LoginListener

    Private form As New LoginAdapter

    Public Sub New()
        MyBase.init()
        form.getObservable().addListener(Me)
    End Sub

    Protected Overrides Function getFormAdapter() As FormAdapter(Of System.Windows.Forms.Form, FormListener)
        Return form.getAsFormAdapter()
    End Function

    Public Sub loginPerformed(ByRef name As String, ByRef password As String) Implements LoginListener.loginPerformed
        Dim tokens As String() = name.Split(".")
        If tokens.Length <> 2 Then
            Me.form.loginFailed()
            Exit Sub
        End If
        Dim mitarbeiter As New Mitarbeiter
        mitarbeiter.vorname = tokens(0)
        mitarbeiter.nachname = tokens(1)
        mitarbeiter.passwort = password
        Dim success As Boolean = Context.LOGIN_SERVICE.login(mitarbeiter)
        If success Then
            Navigation.getInstance.toMenu(Me)
        Else
            Me.form.loginFailed()
        End If
    End Sub
End Class